<template>
    <div>
        <p>
            <input type="text" placeholder="用户名" v-model="username">
        </p>
        <p>
            <input type="text" placeholder="密码" v-model="pwd">
        </p>
        <p><button @click="loginFn">登录</button></p>
    </div>
</template>

<script>
import axios from 'axios';
export default {
    name: '',
    data() {
        return {
            username: '',
            pwd: ''
        };
    },
    methods: {
        async loginFn() {
            if (this.username && this.pwd) {
                const res = await axios.post('http://kumanxuan1.f3322.net:8001/auth/loginByWeb', {
                    username: this.username,
                    pwd: this.pwd
                })

                // console.log(1, res);
                if (res.data.errno == 0) {
                    // 将token 存到本地
                    localStorage.setItem('token', res.data.data.token)
                    // 跳转到首页
                    this.$router.push('/home')
                }
            }
        }
    },
    mounted() {
        console.log(22, this.$route);
    }
}
</script>
<style scoped>

</style>